package com.igeek.boot.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.boot.entity.ContractApprovals;
import com.igeek.boot.entity.Contracts;
import com.igeek.boot.mapper.ContractApprovalsMapper;
import com.igeek.boot.service.IContractApprovals;
import com.igeek.boot.vo.PageQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class ContractApprovalsImpl extends ServiceImpl<ContractApprovalsMapper, ContractApprovals> implements IContractApprovals {

    @Autowired
    private ContractApprovalsMapper contractApprovalsMapper;
    @Override
    public boolean addApproval(Contracts contracts) {
        ContractApprovals approvals = new ContractApprovals();
        approvals.setContractID(contracts.getContractId());
        approvals.setApprovalDate(LocalDate.now());
        approvals.setApprovalStatus("审批中");
        int insert = baseMapper.insert(approvals);
        return insert>0;
    }

    @Override
    public boolean updateApproval(Integer id, String status) {
        UpdateWrapper<ContractApprovals> wrapper = new UpdateWrapper<>();
        ContractApprovals approvals = new ContractApprovals();
        wrapper.eq("approvalID",id);
        approvals.setApprovalStatus(status);
        int i = baseMapper.update(approvals, wrapper);
        return i>0;
    }


    @Override
    public boolean updateComment(ContractApprovals approvals) {
        int i = baseMapper.updateById(approvals);
        return i>0;
    }

    //审批流程分页查询  加上合同信息
    @Override
    public Page<ContractApprovals> findPageByApp(PageQueryVO pageQueryVO) {
        //1.封装分页条件
        Page<ContractApprovals> page = new Page<>(pageQueryVO.getCurrentPage(),  pageQueryVO.getPageSize());
        //封装查询条件
        Page<ContractApprovals> pages=  contractApprovalsMapper.findPageByApp(page,pageQueryVO.getQueryString());
        return pages;
    }

    @Override
    public boolean delContract(Integer id) {
        boolean b = baseMapper.delContract(id);
        return b;
    }
}
